<template>
    <div class="container">
        <div class="flex-container">
            <div class="flex-item">
                <div class="date-c">
                    <div class="date" @click="selectTime(0)">开始日期：{{startTime?$moment(startTime).
                        format('YYYY-MM-DD HH:mm'):"不限"}}
                    </div>
                    <div class="date" @click="selectTime(1)"
                         style="margin-top: 4px">截止日期： {{endTime?$moment(endTime).format('YYYY-MM-DD HH:mm'):"不限"}}
                    </div>
                    <div>
                        <el-button type="primary" size="small" @click="searchData(0)">确定</el-button>
                        <el-button type="default" size="small" @click="searchData(1)">重置</el-button>
                    </div>
                </div>
            </div>
        </div>


        <el-table v-loading="menLoading" :data="menList" class="el-mb-15" stripe>
            <el-table-column prop="ordernumber" label="订单号"/>
            <el-table-column prop="username" label="名称"/>
            <el-table-column prop="znumber" label="总重量"/>
            <el-table-column prop="price" label="总价格"/>
            <el-table-column label="下单时间">
                <template slot-scope="scope">
                    {{$moment(parseInt(scope.row.create_time) * 1000).format('YYYY-MM-DD HH:mm:ss')}}
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
            @size-change="eventUpdateRequestLimit" @current-change="onLoadMenDian"
            :current-page="menQuery.page" :page-size="menQuery.list_rows" :total="menQuery.total"
            :page-sizes="[10, 50, 100, 200, 300]"
            layout="total, sizes, prev, pager, next, jumper"
        ></el-pagination>


        <van-popup v-model="timeSection.show" position="bottom" :close-on-click-overlay="false">
            <div v-show="curTime==0">
                <van-datetime-picker v-model="curTimeValue" @cancel="timeSection.show = false"
                                     @confirm="startTimeSection" type="datetime"/>
            </div>
            <div v-show="curTime==1">
                <van-datetime-picker v-model="curTimeValue" @cancel="timeSection.show = false"
                                     @confirm="endTimeSection" type="datetime"/>
            </div>
        </van-popup>
    </div>
</template>

<script>

    import fly from "../../../src/libs/js/request.js"
    import {DatetimePicker, Popup} from 'vant';

    export default {
        name: 'salesmanIndexs',
        components: {
            [DatetimePicker.name]: DatetimePicker, [Popup.name]: Popup,

        },
        props:["groupid","userId"],
        data() {
            return {

                menList: [/*{
                    "ordernumber": "2020040209201815857904182932",
                    "id": 293,
                    "isbaozhi": 0,
                    "user_id": 75,
                    "delivery_method": 0,
                    "znumber": "2",
                    "zweight": null,
                    "status": 5,
                    "create_time": "1585790418",
                    "end_time": "1585791336",
                    "type": 1,
                    "price": 2,
                    "paytype": 0,
                    "pay_time": null,
                    "detail": [
                        {
                            "id": 366,
                            "garbageid": "82,80,",
                            "stock_id": 0,
                            "danweiming": "kg",
                            "garbageunitid": 196,
                            "bprice": "1",
                            "weighting_num": 2,
                            "price": "2.0",
                            "garbagename": "废铜"
                        }
                    ],
                    "username": "tian"
                }*/],


                menFinished: false,
                menLoading: false,
                menQuery: {
                    page: 0,
                    list_rows: 10,
                },
                timeSection: {
                    show: false,
                },
                curTime: 0,
                curTimeValue: "",
                startTime: "",
                endTime: ""
            }
        },
        mounted() {

            this.onLoadMenDian();
        },
        methods: {

            selectTime(index) {
                this.curTime = index;
                this.timeSection.show = true
            },
            startTimeSection(data) {
                console.log('data ', data)
                this.startTime = data.getTime();
                this.timeSection.show = false
            },
            endTimeSection(data) {
                this.endTime = data.getTime();
                this.timeSection.show = false
            },
            searchData(index) {
                if (index == 1) {
                    this.startTime = "";
                    this.endTime = "";
                }

                this.onLoadMenDian()
            },
            eventUpdateRequestLimit(limit) {

                this.menQuery = {
                    page: 0,
                    list_rows: limit,
                    total: 0
                };
                this.onLoadMenDian();
            },
            async onLoadMenDian() {
                this.menLoading = true;
                let params = this.menQuery;
                params.token = this.$store.state.options.user.token;
                params.groupid = parseInt(this.groupid) + 1;
                params.userId = this.userId;
                params.status = 5;
                params.startTime = this.startTime ? parseInt(this.startTime / 1000) : "";
                params.endTime = this.endTime ? parseInt(this.endTime / 1000) : "";

                let res = await fly.post("/api/home/order/getlist", params);
                if (res.code == 200) {
                    if (res.data.data) {
                        this.menList = res.data.data ? res.data.data : [];
                        this.menQuery.total = res.data.total
                    }
                }
                this.menLoading = false;
            },


        }
    }
</script>

<style lang="scss" scoped>
    .date-c {
        padding: 10px;
        font-size: 14px;
        height: 80px;
        background-color: white;
        display: flex;
        align-items: center;

        .date {
            padding: 8px 20px;
            border: 1px solid #dddfe2;
            width: 200px;
            border-radius: 5px;
            display: inline-block;
            margin-right: 10px;
        }
    }

    .searchBtn {
        display: inline-block;
        padding: 5px 15px;
        font-size: 12px;
        text-align: center;
        color: white;
        background-color: #00CC00;
        margin-top: 5px;
        margin-right: 10px;
    }

    .bac-grey {
        background-color: #A3A3A3 !important;
    }

    .title {
        padding: 10px 10px;
        background-color: #EEEEEE;
    }

    .list {
        padding: 10px;
        font-size: 14px;
        border-bottom: 1px solid #EEEEEE;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .page-top {
        width: 100%;
        height: 3rem;
        position: relative;

        .notice {
            position: absolute;
            top: 0rem;
            width: 100%;
            margin: 0rem;
            padding: 0.7rem 1rem;
            display: flex;
            background: rgba(255, 247, 209, 1);
            z-index: 1;
            box-sizing: border-box;

            dt {
                padding-right: 1rem;

                img {
                    width: 1.4rem;
                }
            }

            dd {
                white-space: nowrap;
                flex: 1;
                margin: 0rem;
                padding: 0rem;
                color: #ff9000;
                font-size: 1.3rem;
            }
        }
    }


</style>
